package main

import (
	"io/ioutil"
	"iot-base/common/notify"
	"os"

	"gopkg.in/yaml.v2"
)

type BOXConfig struct {
	CheckMode    string //tcp http ping 默认为http
	CheckTimeout int    //对tcp和http有效
	//CheckPriod   int    //定时器周期
}

var confg BOXConfig

func init() {
	confg.CheckMode = "tcp"
	confg.CheckTimeout = 1
	loadCfgFile()
	var id string
	notify.SubMsg(false, "templateChanged", &id, func(topic string, body interface{}) {
		idForce, ok := body.(*string)
		if ok && idForce != nil {
			chanForID <- *idForce
		}
	})

}

func loadCfgFile() {
	path := "../../../cfg/box.yaml"
	yamlFile, err := ioutil.ReadFile(path)
	if err == nil {
		data, err := yaml.Marshal(&confg)
		if err == nil {
			ioutil.WriteFile(path, data, os.ModePerm)
		}
	} else {
		yaml.Unmarshal(yamlFile, &confg)
	}
}
